/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package persistencia.conexao;

import groovy.lang.GroovyClassLoader;
import groovy.sql.Sql;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.codehaus.groovy.control.CompilationFailedException;

/**
 *
 * @author André
 */
public class Conexao implements IConexao{

    private Sql conexao;
    private static Conexao instance;

    public static Conexao getInstance() {
        if (instance == null) {
            instance = new Conexao();
        }
        return instance;
    }

    private Conexao() {
        try {
            GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
            Class classeProxy = groovyClassLoader.parseClass(
                    //new File("./src/java/persistencia/conexao/Conexao.groovy"));
                    new File("D:/UEFS/Implementação TCC/codigos/CondicaoCompraWS/src/java/persistencia/conexao/Conexao.groovy"));
            IConexao conn = (IConexao) classeProxy.newInstance();
            conexao = conn.getConexao();
            if (conexao == null) {
                System.out.println("getConexao eh null");
            } else {
                System.out.println("getConexao NAO eh null");
            }
            System.out.println("Conexao --> " + conexao.getConnection());
        } catch (InstantiationException ex) {
            Logger.getLogger(Conexao.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(Conexao.class.getName()).log(Level.SEVERE, null, ex);
        } catch (CompilationFailedException ex) {
            Logger.getLogger(Conexao.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Conexao.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public Sql getConexao() {
        return conexao;
    }    
}
